from django.contrib.auth.models import Permission
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from rest_framework.views import APIView
from apps.meiduo_admin.serializers.permission import *
from apps.meiduo_admin.utils import PageNum

class PermissionModelViewSet(ModelViewSet):
    """权限管理"""
    serializer_class = PermissionSerializers
    queryset = Permission.objects.all()
    pagination_class = PageNum


class Content_typeAPIView(APIView):
    """保存权限"""
    def get(self,request):
        data = ContentType.objects.all()
        slz = Content_typeSerializer(instance=data,many=True)

        return Response(slz.data)

class GroupModelViewSet(ModelViewSet):
    """组管理"""
    serializer_class = GroupModelSerializer
    queryset = Group.objects.all()
    pagination_class = PageNum

class GroupSimpleAPIView(APIView):
    """新增组"""
    def get(self,request):
        data = Permission.objects.all()
        slz = PermissionSerializers(instance=data,many=True)
        return Response(slz.data)


class AdminModelViewSet(ModelViewSet):
    """管理员管理"""
    serializer_class = AdminModelSerializer
    queryset = User.objects.filter(is_staff=True)
    pagination_class = PageNum



class AdminSimpleAPIView(APIView):
    """获取分组数据表"""
    def get(self,request):
        data = Group.objects.all()
        slz = GroupModelSerializer(instance=data,many=True)
        return Response(slz.data)